<?php

class UseBoxApp extends MemberbaseApp
{
	function index()
	{
		$sqldb=&sqldb();

		$uid=$this->visitor->get("user_id");
		$uid=empty($uid)?0:intval($uid);

		$k = empty($_REQUEST['k']) ? '' : $_REQUEST['k'];

		$conditions = ' 1=1';
		if($k){
			$conditions.=" and (s.BOX_NO like '%".$k."%' or s.SEAL_NO like '%".$k."%' or s.SHIP_OVOY like '%".$k."%' or s.TD_NO like '%".$k."%')";
				
			$db=&db();

			$page = $this->_get_pagen(10);

			$sql="select * from
		(select s.*,ROW_NUMBER() OVER (ORDER BY EC_DD desc) AS RowNumber 
		from dbo.T_Stock as s where $conditions) T_Stock where RowNumber > ".$page['s']." 
		AND RowNumber <= ".$page['e']." ORDER BY EC_DD desc";

			$plan=$sqldb->getAll($sql);
			$list=array();
			if($plan){
				foreach ($plan as $v){
					if($v['EC_DD']){
						$v['EC_DD']=gmstr2time($v['EC_DD']);
					}

					$list[]=$v;
				}
			}


			$sql="select * from
		(select s.XX,s.CC from dbo.T_Stock as s where $conditions) T_Stock";

			$box=$sqldb->getAll($sql);
			$boxlist=array();
			if($box){
				foreach ($box as $v){
					$boxlist[$v['CC'].$v['XX']]['zu']=$v['CC'].$v['XX'];
					$boxlist[$v['CC'].$v['XX']]['item'][]=$v;
				}
			}
			$count="统计:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
			if($boxlist){
				foreach ($boxlist as $v){
					$count.=$v['zu']."*".count($v['item'])."&nbsp;&nbsp;";
				}
			}else{
				$count="";
			}
			$this->assign('box', $count);

			$sql="select count(1) from dbo.T_Stock as s where $conditions";
			$c=$sqldb->getOne($sql);
			//$this->json_result($list);

			$page['item_count'] = $c;
			$this->_format_pageweb($page);
			$this->assign('page_info', $page);

			$this->assign('plan', $list);
			
			$this->assign('no_search', false);
				
		}else{
			$this->assign('no_search', true);
		}

		$this->display('usebox.html');
	}

}

?>
